<script setup lang="ts">
  import { ref, reactive, onMounted, } from "vue"
  import { createMessage } from '@/Public-UIlibrary/pb-message/method'
  import { getMealTimeslist } from '@/api/System'
  import SetMealModal from './components/SetMealModal.vue'
  const pages = reactive({
    currentPage: 1,
    pageSize: 15,
    total: 100,
  })
  let loading = ref(false)
  let mealData = reactive([
  ])
  const mealFormRef = ref()
  const SetMealModalRef = ref()
  const mealSearchForm = reactive({
    mealTimesName: '',
    tenantLevelId: '',
  })
  const mealColumn = [{

    key: 'mealTimesName',
    name: '餐段名称',
  },
  {
    key: 'beginTime',
    name: '餐段开始时间',


  },
  {
    key: 'endTime',
    name: '餐段结束时间',


  },

  {
    slot: 'operation',
    name: '操作',
    width: 200,
  }]
  // 层级列表
  let levelList = ref([

  ])
  // 初始化
  const onit = () => {
    getMealTimeslistApi()
  }
  const onConfirmModal = () => {
    onit()
  }
  // 查询
  const onSearch = () => {
    getMealTimeslistApi()
  }
  // 重置
  const onReset = () => {
    console.log(mealFormRef);
    pages.currentPage = 1
    mealFormRef.value.resetFields()
    getMealTimeslistApi()
  }
  // 添加
  const onAddFn = () => {
    SetMealModalRef.value.onShow()
  }
  // 编辑 
  const onEdit = (row) => {
    SetMealModalRef.value.onShow(row)
  }
  // 分页改变
  const onPagesChange = () => {
    getMealTimeslistApi()

  }
  // 获取角色列表接口
  const getMealTimeslistApi = async () => {
    loading.value = true
    let { total, ...arg } = pages
    let res = await getMealTimeslist(
      {
        mealTimesName: mealSearchForm.mealTimesName
      }
    )
    loading.value = false
    if (res.code == 2000) {
      mealData = [...res.data]
      pages.total = res.data.total
    }
  }
  onMounted(() => {
    onit()
  })
</script>

<template>
  <div class="app-container flex flex-col">
    <SearchCard @onSearch="onSearch" @onReset="onReset()">
      <el-form ref="mealFormRef" :model="mealSearchForm" label-width="auto" :inline="true">
        <el-form-item label="餐段名称" prop="mealTimesName">
          <pb-input v-model="mealSearchForm.mealTimesName" placeholder="请输入餐段名称" />
        </el-form-item>
      </el-form>
    </SearchCard>
    <pb-card padding="0px " class="flex-1">
      <div v-hasPerm="'center:meal:add'">
        <ContentOperation>
          <pb-button size="small" plain @click="onAddFn">+添加</pb-button>
        </ContentOperation>
      </div>

      <pb-card>
        <pb-table :tableData='mealData' :column='mealColumn' :loading="loading">
          <template v-slot:operation="scope">
            <pb-button text size="small" v-hasPerm="'center:meal:edit'" @click="onEdit(scope.row)">编辑</pb-button>
          </template>
        </pb-table>
        <!-- <pb-pagination v-model:currentPage="pages.currentPage" v-model:pageSize="pages.pageSize"
          @onChange="onPagesChange" :total="pages.total"></pb-pagination> -->
      </pb-card>
    </pb-card>
    <SetMealModal ref="SetMealModalRef" @onConfirmModal="onConfirmModal"></SetMealModal>
  </div>
</template>

<style lang="less" scoped></style>